package com.lagou.edu.controller;

import com.lagou.edu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/register/{email}/{password}/{code}")
    public int register(@PathVariable("email") String email,
                        @PathVariable("password") String password,
                        @PathVariable("code") String code) {
        return userService.register(email, password, code);
    }

    @GetMapping("/isRegistered/{email}")
    public boolean validate(@PathVariable("email") String email) {
        return userService.isRegistered(email);
    }

    @GetMapping("/login/{email}/{password}")
    public String login(@PathVariable("email") String email,
                        @PathVariable("password") String password) {
        return userService.login(email, password);
    }

    @GetMapping("/info/{token}")
    public String info(@PathVariable("token") String token) {
        return userService.info(token);
    }

}